package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo10 {
    public static void main(String[] args) {

        UserInfo user = InputUtil.getInputObject(new UserInfo(),"注册新用户");
        try (Connection conn = DBUtil.getConnection();){
            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                         "VALUES (?,?,?,?)";
            PreparedStatement stat = conn.prepareStatement(sql);
            stat.setString(1,user.getUsername());
            stat.setString(2,user.getPassword());
            stat.setString(3,user.getNickname());
            stat.setInt(4,user.getAge());
            int num = stat.executeUpdate();
            System.out.println(num>0?"加入成功":"加入失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
